package com.wy.panda.mybatisplus;

import java.util.Date;

import org.apache.ibatis.reflection.MetaObject;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

import lombok.extern.slf4j.Slf4j;

/**
 * mybatis-plus的自动填充功能
 * @author wangyuan
 * @since 2020年1月20日 上午10:37:23
 *
 */
@Slf4j
public class PandaMetaObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		log.debug("start insert fill");
		Date currentDate = new Date();
		strictInsertFill(metaObject, "createdUser", String.class, null);
		strictInsertFill(metaObject, "createdTime", Date.class, currentDate);
		strictInsertFill(metaObject, "updatedUser", String.class, null);
		strictInsertFill(metaObject, "updatedTime", Date.class, currentDate);
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		log.debug("start update fill");
		Date currentDate = new Date();
		strictUpdateFill(metaObject, "updatedUser", String.class, null);
		strictUpdateFill(metaObject, "updatedTime", Date.class, currentDate);
	}

}
